/**
 * 新增文章的js
 * */

/*==========发表文章start==========*/
$(function () {
    $('#public-article').on('click', function () {
        // 当文章标题及内容不为空的时候打开弹框
        if ($('#article-title').val().trim() && editor.getMarkdown().trim()) {
            $('#article-model').modal('show');
        } else {
            alert('请输入内容')
        }
    })

    // 发表文章
    $('#send-article').on('click', function () {
        let content = editor.getMarkdown();
        let title = $('#article-title').val();
        let category = $(".category-list input[type='radio']:checked").val();
        let type = $('#article-type').val();
        $.ajax({
            url: "/article/new_article/",
            method: 'post',
            data: {
                content: content,
                title: title,
                category: category,
                type: type
            },
            success: function (data) {
                $('#article-model').modal('hide');
                $('#article-info').modal('show');
                if (data.code == 0) {
                    $('#article-info .modal-body').html('发表博文成功');
                } else {
                    $('#article-info .modal-body').html('发表博文失败');
                }

            },
            error: function (error) {
                console.log(error)
            }
        })
    })
})
/*==========发表文章end==========*/